﻿@using CommonApp
@model IList<BankApp.Models.ExchangeRate>

@{
    ViewBag.Title = "Exchange Rates";
}
<script type="text/javascript" src="@Url.Content("~/Scripts/filter.js")"></script>

<h2>Exchange rates </h2> 
<div class="commonFilters" style="text-align: left;">
    <span style="margin: 20px 10px;"><a id="weekFilter" class="filter" href="" >Week</a></span>
    <span style="margin: 20px 10px;"><a id="monthFilter" class="filter" href="" >Month</a></span>
    <span style="margin: 20px 10px;"><a id="todayFilter" class="filter" href="" >Today</a></span>
</div>

<form id="filterForm" method="post" action="/ExchangeRates/Index">
    <table>
        <tr>
            <td><span>From:</span></td>
            <td><input id="fromDate" name="fromDate" type="text" value="@ViewBag.FromDate"/></td>
        </tr>
        <tr>
            <td><span>To:</span></td>
            <td><input id="toDate" name="toDate" type="text" value="@ViewBag.ToDate"/></td>
        </tr>
        <tr>
            <td><span>Currency: </span></td>
            <td>@Html.DropDownList("currency", new List<SelectListItem> {
                    new SelectListItem { Text = "All", Value = null },
                    new SelectListItem { Text = "USD", Value = "USD", Selected = ViewBag.Currency == "USD" },
                    new SelectListItem { Text = "EUR", Value = "EUR", Selected = ViewBag.Currency == "EUR" },
                    new SelectListItem { Text = "CAD", Value = "CAD", Selected = ViewBag.Currency == "CAD" },
                    new SelectListItem { Text = "AUD", Value = "AUD", Selected = ViewBag.Currency == "AUD" },
                    new SelectListItem { Text = "JPY", Value = "JPY", Selected = ViewBag.Currency == "JPY" },})</td>
        </tr>
    </table>

    <input type="submit" value="Filter"/>
    <br />
</form>

<br/>

@{
    var grid = new WebGrid(
        source: Model,
        canPage: false);
     }

@if (Model.Count > 0)
{
    @grid.GetHtml(
        tableStyle: "grid",
        headerStyle: "header",
        rowStyle: "row",
        footerStyle: "footer",
        alternatingRowStyle: "row",
        columns: grid.Columns (
            grid.Column("Date", "Date", style:"dateCol"),
            grid.Column("Currency", "Currency", style:"textCol block"),
            grid.Column("Ask", "Ask", style:"textCol block"),
            grid.Column("Bid", "Bid", style:"textCol block"),
                            grid.Column(format: (item) => (item.Date.Date == DateTime.Today && User.IsInRole("admin") && item.Currency != "BYR")
                ? Html.ActionLink("Edit", "Edit", new { c = item.Currency, ask = item.Ask, bid = item.Bid })
                : null)
        ))
}
else
{
    <label> No information available </label>   
}
<br />
@Html.ActionLink("New", "Create").If(User.IsInRole("admin"))
